package com.okcl.manage.controller;

import com.okcl.common.annotation.Anonymous;
import com.okcl.common.core.controller.BaseController;
import com.okcl.common.core.domain.AjaxResult;
import com.okcl.manage.domain.dto.BorrowRecordDto;
import com.okcl.manage.service.IHomeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@Anonymous
@RequestMapping("/home")
@Slf4j
public class HomeController extends BaseController {
    private final IHomeService homeService;

    /**
     * 获取图书分类信息
     *
     * @return
     */
    @GetMapping("/getCategoryInfo")
    public AjaxResult getCateGoryInfo() {
        return AjaxResult.success(homeService.getCateGoryInfoList());
    }

    /**
     * 获取图书信息
     *
     * @return
     */
    @GetMapping("/getBookInfo")
    public AjaxResult getBookInfo() {
        return AjaxResult.success(homeService.getBookInfoList());
    }

    /**
     * 提交用户借阅信息
     *
     * @param borrowRecordDto
     * @return
     */
    @PostMapping("/submitBorrowRecord")
    public AjaxResult submitBorrowRecord(@RequestBody BorrowRecordDto borrowRecordDto) {
        log.info("提交用户借阅信息：{}", borrowRecordDto.getBorrowDate().toString());
        int i = homeService.submitBorrowRecord(borrowRecordDto);
        return toAjax(i);
    }
}
